<template>
  <div>
    <el-dialog
      v-dialogDrag
      title="仓库分组"
      model
      :visible.sync="openCustomer"
      :close-on-click-modal="false"
      width="30%"
      :before-close="beforeClose"
    >
      <div class="public-form">
        <el-tree
          node-key="fid"
          :data="materialGroupL"
          :props="defaultProps"
          check-on-click-node
          accordion
          @node-click="handleNodeClick"
        />
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { queryStockGroup } from '@/api/repertory/stock'

export default {
  data() {
    return {
      openCustomer: true,
      materialGroupL: [], // tree组数据
      defaultProps: {
        children: 'details',
        label: 'fname'
      },
      treeClickCount: 0,
      proValue: {}
    }
  },
  created() {
    this.getMaterialGroupL()
  },
  methods: {
    // 获取树型控件数据
    async getMaterialGroupL() {
      const { data: RES } = await queryStockGroup({})
      this.materialGroupL = RES
    },
    // 仓库分组
    handleNodeClick(item) {
      this.treeClickCount++
      if (this.treeClickCount >= 2) return
      this.timer = window.setTimeout(() => {
        if (this.treeClickCount === 1) {
          this.treeClickCount = 0
        } else if (this.treeClickCount > 1) {
          this.treeClickCount = 0
          this.proValue = item
          this.$emit('stock', item)
        }
      }, 300)
    },
    beforeClose() {
      this.$emit('stock', {})
    }
  }
}
</script>

<style scoped lang="scss">

</style>

